const { getSiteInfo, updateSiteInfo } = require('../controller/site')
const { SuccessModel, ErrorModel } = require('../model/resModel')

const handleSiteRouter = (req, res) => {
  // 站点信息
  if (req.method === 'GET' && req.path === '/api/site/info') {
    return getSiteInfo(req.query).then(data => {
      if (data) {
        return new SuccessModel(data)
      } else {
        return new ErrorModel(data)
      }
    })
  }

  // 更新站点
  if (req.method === 'POST' && req.path === '/api/site/update') {
    return updateSiteInfo(req.body).then(data => {
      if (data) {
        return new SuccessModel({}, '更新成功')
      } else {
        return new ErrorModel({}, '更新失败')
      }
    })
  }
}

module.exports = handleSiteRouter
